package com.hxkj.utils;

import com.hxkj.domain.bo.Form;

/**
 * 生成表单
 * <p>
 * Create by chenwei on 2018/8/15 16:00
 */
public class FormUtil {

    /**
     * 生成支付表单
     *
     * @return string
     */
    public static String createForm(Form form) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("<form style='display:none;' id='formpay' name='formpay' method='post' action='http://zhifu.baike.com/pay'>");
        stringBuffer.append("<input name='goodsname' id='goodsname' type='text' value=\"" + form.getGoodsName() + "\" />");
        if (StringUtils.isBlank(form.getIstype())) {
            // 默认为支付宝支付 1 为支付宝 2 为微信
            stringBuffer.append("<input name='istype' id='istype' type='text' value=\"" + form.getIstype() + "\" />");
        } else {
            stringBuffer.append("<input name='istype' id='istype' type='text' value=\"" + form.getIstype() + "\" />");
        }
        stringBuffer.append("<input name='key' id='key' type='text' value=\"" + form.getKey() + "\"/>");
        stringBuffer.append("<input name='notify_url' id='notify_url' type='text' value=\"" + form.getNotify_url() + "\"/>");
        stringBuffer.append("<input name='orderid' id='orderid' type='text' value=\"" + form.getOrderid() + "\"/>");
        stringBuffer.append("<input name='orderuid' id='orderuid' type='text' value=\"" + form.getOrderuid() + "\"/>");
        stringBuffer.append("<input name='price' id='price' type='text' value=\"" + form.getPrice() + "\"/>");
        stringBuffer.append("<input name='return_url' id='return_url' type='text' value=\"" + form.getReturn_url() + "\"/>");
        stringBuffer.append("<input name='uid' id='uid' type='text' value=\"" + form.getUid() + "\"/>");
        stringBuffer.append("<input type='submit'>");
        stringBuffer.append("</form>");
        stringBuffer.append("<script type=\"text/javascript\">");
        stringBuffer.append("document.formpay.submit()");
        stringBuffer.append("</script>");

        return stringBuffer.toString();
    }
}
